package com.xyht.sca_s.student_manage_system.modules.student_subsidies.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.student_subsidies.entity.req.SmsStudentSubsidiesTaskReq;
import com.xyht.sca_s.student_manage_system.modules.student_subsidies.service.SmsStudentSubsidiesTaskService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 学生助学金申请任务 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-02-26
 */
@RestController
@RequestMapping("/subsidies/task")
@SecretBody
public class SmsStudentSubsidiesTaskController {
    @Autowired
    private SmsStudentSubsidiesTaskService smsStudentSubsidiesTaskService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "教师助学金任务添加")
    @PostMapping("/add")
    public ResponseResult addStudentInfo(@RequestBody SmsStudentSubsidiesTaskReq smsStudentSubsidiesTaskReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesTaskService.addSubsidiesTask(smsStudentSubsidiesTaskReq, user_id);
    }

    @ApiModelProperty(value = "教师助学金任务关闭")
    @PostMapping("/close")
    public ResponseResult closeSubsidiesTask(@RequestBody SmsStudentSubsidiesTaskReq smsStudentSubsidiesTaskReq) {
        return smsStudentSubsidiesTaskService.closeSubsidiesTask(smsStudentSubsidiesTaskReq);
    }

    @ApiModelProperty(value = "教师助学金任务删除")
    @PostMapping("/delete")
    public ResponseResult deleteSubsidiesTask(@RequestBody SmsStudentSubsidiesTaskReq smsStudentSubsidiesTaskReq) {
        return smsStudentSubsidiesTaskService.deleteSubsidiesTask(smsStudentSubsidiesTaskReq);
    }

    @ApiModelProperty(value = "教师助学金任务更新(任务名修改)")
    @PostMapping("/update")
    public ResponseResult updateSubsidiesTask(@RequestBody SmsStudentSubsidiesTaskReq smsStudentSubsidiesTaskReq) {
        return smsStudentSubsidiesTaskService.updateSubsidiesTask(smsStudentSubsidiesTaskReq);
    }

    @ApiModelProperty(value = "助学金任务列表")
    @GetMapping("/list")
    public ResponseResult getSubsidiesTaskList(HttpServletRequest request,
                                               @RequestParam(value = "is_close", required = false) Integer is_close,
                                               @RequestParam(value = "search_str", required = false) String search_str,
                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesTaskService.getSubsidiesTaskList(pageNum, pageSize, is_close, user_id,search_str);
    }

    @ApiModelProperty(value = "助学金任务详情")
    @GetMapping("/detail")
    public ResponseResult getSubsidiesTaskDetail(HttpServletRequest request,
                                                 @RequestParam(value = "task_id") String task_id) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentSubsidiesTaskService.getSubsidiesTaskDetail(task_id, user_id);
    }


}

